package leetcode;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2022-02-15
 * Time: 19:19
 */
public class Day_02 {
    public static void main(String[] args) {

    }
}
class Solution {
    public List<Integer> luckyNumbers (int[][] matrix) {
        int m=matrix.length,n=matrix[0].length;
        Set<Integer> minSet=new HashSet<>();
        List<Integer> res=new ArrayList<>();
        for(int i=0;i<m;i++){
            int min=Integer.MAX_VALUE;
            for(int j=0;j<n;j++){
                min=Math.min(min,matrix[i][j]);
            }
            minSet.add(min);
        }
        for(int j=0;j<n;j++){
            int max=Integer.MIN_VALUE;
            for(int i=0;i<m;i++){
                max=Math.max(max,matrix[i][j]);
            }
            if(minSet.contains(max)){
                res.add(max);
            }
        }
        return res;
    }
}